package com.abaaba.project2.controller;


import com.abaaba.project2.bean.Ad;
import com.abaaba.project2.bean.bo.AdReqBo;
import com.abaaba.project2.bean.bo.AddAdvertisementReqBo;
import com.abaaba.project2.bean.bo.BaseReqBo;
import com.abaaba.project2.bean.data.AdvertisementInfo;
import com.abaaba.project2.bean.vo.AdvertisementListVO;
import com.abaaba.project2.bean.vo.AdvertisementVo;
import com.abaaba.project2.bean.vo.BaseRespVo;
import com.abaaba.project2.service.AdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/ad")
public class AdvertisementController {

    @Autowired
    AdvertisementService advertisementService;

    /**
     * 显示广告列表
     */
    @RequestMapping("/list")
    public BaseRespVo list(AdReqBo reqBo){
     AdvertisementListVO advertisementListVO = advertisementService.queryAd(reqBo);
        return BaseRespVo.ok(advertisementListVO);
    }

    /**
     * 添加广告
     * @param addAdvertisementReqBo
     * @return
     */
    @RequestMapping("/create")
    public BaseRespVo create(@RequestBody AddAdvertisementReqBo addAdvertisementReqBo){
      AdvertisementVo advertisementVo = advertisementService.createAdvertisement(addAdvertisementReqBo);
        return BaseRespVo.ok(advertisementVo);
    }

    /**
     * 编辑广告
     * @param advertisementInfo
     * @return
     */
    @RequestMapping("/update")
    public BaseRespVo update(@RequestBody AdvertisementInfo advertisementInfo){

        AdvertisementInfo advertisementInfo1 = advertisementService.updateAdvertisement(advertisementInfo);

        return BaseRespVo.ok(advertisementInfo1);
    }

    /**
     * 删除广告（逻辑删除）
     * @param advertisementInfo
     * @return
     */
    @RequestMapping("/delete")
    public BaseRespVo delete(@RequestBody AdvertisementInfo advertisementInfo){

        advertisementService.deleteAdvertisement(advertisementInfo.getId());

        return BaseRespVo.ok();
    }
}
